package edu.example;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Container;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import java.util.Collection;
import java.util.Iterator;
import java.util.Vector;

import javax.swing.ButtonGroup;
import javax.swing.JButton;
import javax.swing.JComponent;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
import javax.swing.JScrollPane;
import javax.swing.JTabbedPane;
import javax.swing.JTable;
import javax.swing.JTextArea;
import javax.swing.JTextField;


public class viewAppFrame extends JFrame
{
	private Application app;
	private OfficialTestScore ots;
	
	private	JTabbedPane tabbedPane;
	
	private JPanel basicInfoPanel;
	private JPanel testInfoPanel;
	private JPanel academicInfoPanel;
	private JPanel classInfoPanel;
	private JPanel summaryPanel;
	private JPanel otsPanel;
	
	private JPanel buttonPanel;
	private JPanel evaluatePanel;
	private JPanel editPanel;
	private JPanel controlPanel;
	
	private JLabel submissionDateLabel;
	private JTextField submissionDateField;
	
	private JLabel ethnicityLabel;
	private JTextField ethnicityField;
	
	private JLabel raceLabel;
	private JTextField raceField;
	
	private JLabel citizenLabel;
	private JTextField citizenField;
	
	private JLabel phoneLabel;
	private JTextField phoneField;
	
	private JLabel numDesireReviewsLabel;
	private JTextField numDesireReviewsField;
	
	private JLabel tierLabel;
	private JTextField tierTextField;
	private JLabel tierStateLabel;
	
	private JLabel appNumLabel;
	
	private JLabel nameLabel;
	private JTextField nameTextField;
	
	private JLabel genderLabel;
	private JLabel DOBLabel;
	private JLabel emailLabel;
	private JLabel pResidentLabel;
	
	private JTextField genderTextField;
	private JTextField DOBTextField;
	private JTextField emailTextField;
	private JTextField pResidentTextField;
	
	private JLabel appTypeLabel;
	private JTextField appTypeField;
	
	private JLabel SBUIDLabel;
	private JTextField SBUIDTextField;
	
	private JLabel SBUGPALabel;
	private JTextField SBUGPATextField;
	
	private JLabel TOEFLNetLabel;
	private JTextField TOEFLNetField;
	
	private JLabel GRELabel;
	private JLabel verbalLabel;
	private JLabel quantitativeLabel;
	private JLabel analyticalLabel;
	private JLabel GRESubjectLabel;
	private JLabel GRESubjectScoreLabel;
	private JLabel TOEFLLabel;
	private JLabel verbalPerLabel;
	private JLabel quanPerLabel;
	private JLabel analyPerLabel;
	
	private JTextField verbalTextField;
	private JTextField quantitativeTextField;
	private JTextField analyticalTextField;
	private JTextField verbalPerTextField;
	private JTextField quanPerTextField;
	private JTextField analyPerTextField;
	private JTextField GRESubjectTextField;
	private JTextField GRESubjectScoreTextField;
	private JTextField TOEFLScoureTextField;
	
	private JLabel TOEFLCommentsLabel;
	private JTextArea TOEFLCommentsArea;
	private JScrollPane TOEFLCommentsScrollPanel;
	
	private JLabel gradingScaleLabel1;
	private JTextField gradingScaleField1;
	
	private JLabel gradingScaleLabel2;
	private JTextField gradingScaleField2;
	
	private JLabel gpaLabel;
	
	private JLabel IELTSLabel;
	private JLabel programLabel;
	private JLabel indicateTopicLabel;
	private JLabel institution1Label;

	private JLabel institution2LabeL;
	private JLabel undergraduateRankLabel;
	
	private JLabel gpaYear1Label;
	private JTextField gpaYear1Field;
	
	private JLabel gpaYear2Label;
	private JTextField gpaYear2Field;
	
	private JLabel gpaYear3Label;
	private JTextField gpaYear3Field;
	
	private JLabel gpaYear4Label;
	private JTextField gpaYear4Field;
	
	private JLabel gpaYear5Label;
	private JTextField gpaYear5Field;
	
	private JLabel gpaYear6Label;
	private JTextField gpaYear6Field;
	
	private JLabel gpaYear7Label;
	private JTextField gpaYear7Field;
	
	private JTextField IELTSTextField;
	private JTextField programTextField;
	private JTextField indicateTopicTextField;
	private JTextField institution1TextField;

	private JTextField institution2TextField;
	private JTextField undergraduateRankTextField;
	
	private JLabel ugRankOfLabel;
	private JTextField ugRankOfField;
	
	private JLabel graduateRankLabel;
	private JTextField graduateRankTextField;
	
	private JLabel gRankOfLabel;
	private JTextField gRankOfField;
	
	private JLabel theoryCourseLabel;
	private JTextField theoryCourseField;
	private JLabel theoryScaleLabel;
	private JTextField theoryScaleField;
	private JLabel theoryGradeLabel;
	private JTextField theoryGradeField;
	private JLabel theoryEquivLabel;
	private JTextField theoryEquivField;
	
	private JLabel algorithmCourseLabel;
	private JTextField algorithmCourseField;
	private JLabel algorithmScaleLabel;
	private JTextField algorithmScaleField;
	private JLabel algorithmGradeLabel;
	private JTextField algorithmGradeField;
	private JLabel algorithmEquivLabel;
	private JTextField algorithmEquivField;
	
	private JLabel proglangCourseLabel;
	private JTextField proglangCourseField;
	private JLabel proglangScaleLabel;
	private JTextField proglangScaleField;
	private JLabel proglangGradeLabel;
	private JTextField proglangGradeField;
	private JLabel proglangEquivLabel;
	private JTextField proglangEquivField;
	
	private JLabel osCourseLabel;
	private JTextField osCourseField;
	private JLabel osScaleLabel;
	private JTextField osScaleField;
	private JLabel osGradeLabel;
	private JTextField osGradeField;
	private JLabel osEquivLabel;
	private JTextField osEquivField;
	
	private JLabel GREVLabel;
	private JTextField GREVField;
	
	private JLabel GREVPLabel;
	private JTextField GREVPField;
	
	private JLabel GREQLabel;
	private JTextField GREQField;
	
	private JLabel GREQPLabel;
	private JTextField GREQPField;
	
	private JLabel GREALabel;
	private JTextField GREAField;
	
	private JLabel GREAPLabel;
	private JTextField GREAPField;
	
	private JLabel GRESubLabel;
	private JTextField GRESubField;
	
	private JLabel GRESubSLabel;
	private JTextField GRESubSField;
	
	private JLabel GRESubPLabel;
	private JTextField GRESubPField;
	
	private JLabel toeflTLabel;
	private JTextField toeflTField;
	
	private JLabel toeflLLabel;
	private JTextField toeflLField;
	
	private JLabel toeflRLabel;
	private JTextField toeflRField;
	
	private JLabel toeflSLabel;
	private JTextField toeflSField;
	
	private JLabel toeflWLabel;
	private JTextField toeflWField;
	
	
	private JLabel summaryLabel;
	private JTextArea summaryTextArea;
	private JScrollPane summaryScrollPanel;
	
	private JRadioButton acceptRadioButton;
	private JRadioButton rejectRadioButton;
	private JRadioButton reevaluateRadioButton;
	private JButton viewReviewsButton;
	private JButton addReviewButton;
	private JButton enableEditingButton;
	private JButton viewFileButton;
	private JButton backButton;
	private JButton okButton;
	
	private BackHandler backHandler;
	private ViewReviewsHandler viewReviewsHandler;
	private AddReviewHandler addReviewHandler;
	private EnableEditingHandler enableEditingHandler;
	private OKHandler okHandler;
	private ViewFileHandler viewFileHandler;
	private RadioButtonHandler radioButtonHandler;
	
	private UserManager um;
	private boolean isChair;
	private Reviewer user;
	
	public viewAppFrame(Application initApp, OfficialTestScore initOTS, UserManager initUm)
	{
		ots = initOTS;
		um = initUm;
		isChair = um.isChair();
		user = um.getCurrentUser();
		this.setSize(1280, 720);
		this.setResizable(false);
		app = initApp;
		layoutGUI();
	}

	private void layoutGUI() 
	{
		// size and locate the dialog at the center of the screen
		int w = getWidth();
		int h = getHeight();
		Toolkit tk = Toolkit.getDefaultToolkit();
		Dimension screenSize = tk.getScreenSize();
		int screenWidth = screenSize.width;
		int screenHeight = screenSize.height;
		int x = (screenWidth - w)/2;
		int y = (screenHeight - h)/2;
		setLocation(x,y);
		
		//this.getContentPane().setBackground(Color.WHITE);
		this.setTitle("View Application");
		tabbedPane = new JTabbedPane();
		//tabbedPane.setBackground(Color.WHITE);
		basicInfoPanel = new JPanel();
		//basicInfoPanel.setBackground(Color.WHITE);
		testInfoPanel = new JPanel();
		//testInfoPanel.setBackground(Color.WHITE);
		academicInfoPanel = new JPanel();
		//academicInfoPanel.setBackground(Color.WHITE);
		summaryPanel = new JPanel();
		//summaryPanel.setBackground(Color.WHITE);
		classInfoPanel = new JPanel();
		//classInfoPanel.setBackground(Color.WHITE);
		otsPanel = new JPanel();
		
		evaluatePanel = new JPanel();
		evaluatePanel.setLayout(new FlowLayout(FlowLayout.CENTER));
		//evaluatePanel.setBackground(Color.WHITE);
		
		controlPanel = new JPanel();
		controlPanel.setLayout(new BorderLayout());
		//controlPanel.setBackground(Color.WHITE);
		
		editPanel = new JPanel();
		editPanel.setLayout(new FlowLayout(FlowLayout.CENTER));
		//editPanel.setBackground(Color.WHITE);
		
		submissionDateLabel = new JLabel("Submission Date: ");
		submissionDateField = new JTextField(app.getSubmittedDate());
		submissionDateField.setEditable(false);
		//submissionDateField.setBackground(Color.WHITE);
		
		ethnicityLabel = new JLabel("Ethnicity: ");
		ethnicityField = new JTextField(app.getEthnicity());
		ethnicityField.setEditable(false);
		//ethnicityField.setBackground(Color.WHITE);
		
		raceLabel = new JLabel("Race: ");
		raceField = new JTextField(app.getRace());
		raceField.setEditable(false);
		//raceField.setBackground(Color.WHITE);
		
		citizenLabel = new JLabel("Country of Citizenship: ");
		citizenField = new JTextField(app.getCountryofCitizenship());
		citizenField.setEditable(false);
		//citizenField.setBackground(Color.WHITE);
		
		phoneLabel = new JLabel("Phone Number: ");
		phoneField = new JTextField(app.getCurrentPhone());
		phoneField.setEditable(false);
		//phoneField.setBackground(Color.WHITE);
		
		TOEFLNetLabel = new JLabel("TOEFL Internet: ");
		TOEFLNetField = new JTextField(10);
		TOEFLNetField.setText(app.getTOEFLInternet());
		TOEFLNetField.setEditable(false);
		//TOEFLNetField.setBackground(Color.WHITE);
		
		numDesireReviewsLabel = new JLabel("Number of Desire Reviews: ");
		numDesireReviewsField = new JTextField(app.getNumReviewed()+"/"+app.getNumDesiredReviews());
		numDesireReviewsField.setEditable(false);
		
		
		tierLabel = new JLabel("Tier: ");
		tierTextField = new JTextField(5);
		tierTextField.setText(app.getTier());
		tierTextField.setEnabled(false);
		//tierTextField.setBackground(Color.WHITE);
		String tierState = "Admit";
		/*if (app.getTier()>1.0 && app.getTier()<1.5)
			tierState = "Very likely admit; need interview or additional documents";
		else if (app.getTier()<2.0)
			tierState = "Borderline; need additional review";
		else if (app.getTier()<3.0)
			tierState = "Likely reject, but can be reviewed";
		else tierState = "Reject";*/
		tierStateLabel = new JLabel("("+tierState+")");
		
		appNumLabel = new JLabel("Application #"+app.getApplicantClientID());
		
		nameLabel = new JLabel("Name: ");
		nameTextField = new JTextField(app.getApplicantFirstName()+" "+app.getApplicantMiddleName()+" "+app.getApplicantLastName());
		nameTextField.setEditable(false);
		//nameTextField.setBackground(Color.WHITE);
		
		genderLabel = new JLabel("Gender: ");
		genderTextField = new JTextField(app.getGender());
		genderTextField.setEditable(false);
		
		DOBLabel = new JLabel("Date of Birth: ");
		emailLabel = new JLabel("E-Mail: ");
		
		DOBTextField = new JTextField(app.getDateofBirth()+"/"+app.getDOBDay()+"/"+app.getDOBYear());
		DOBTextField.setEditable(false);
		emailTextField = new JTextField(app.getEmailAddress());
		emailTextField.setEditable(false);
		
		pResidentLabel = new JLabel("Permanent Resident: ");
		pResidentTextField = new JTextField(app.getPermanentResident_yesno());
		pResidentTextField.setEditable(false);
		
		appTypeLabel = new JLabel("Application Type: ");
		appTypeField = new JTextField(app.getApplicationType());
		appTypeField.setEditable(false);
		
		SBUIDLabel = new JLabel("SBU ID: ");
		SBUIDTextField = new JTextField(10);
		SBUIDTextField.setText(app.getSBUID());
		SBUIDTextField.setEnabled(false);
		
		SBUGPALabel = new JLabel("SBU GPA: ");
		SBUGPATextField = new JTextField(5);
		SBUGPATextField.setText(app.getSBUGPA());
		SBUGPATextField.setEnabled(false);
		
		GRELabel = new JLabel("GRE Score: ");
		
		verbalLabel = new JLabel("Verbal: ");
		verbalTextField = new JTextField(10);
		verbalTextField.setText(app.getVerbal());
		verbalTextField.setEditable(false);
		
		quantitativeLabel = new JLabel("Quantitative: ");
		quantitativeTextField = new JTextField(app.getQuantitative());
		quantitativeTextField.setEditable(false);
		
		analyticalLabel = new JLabel("Analytical: ");
		analyticalTextField = new JTextField(app.getAnalytical());
		analyticalTextField.setEditable(false);
		
		verbalPerLabel = new JLabel("Percentile: ");
		verbalPerTextField = new JTextField(app.getVerbalPercentile());
		verbalPerTextField.setEditable(false);
		
		quanPerLabel = new JLabel("Percentile: ");
		quanPerTextField = new JTextField(app.getQuantitativePercentile());
		quanPerTextField.setEditable(false);
		
		analyPerLabel = new JLabel("Percentile: ");
		analyPerTextField = new JTextField(app.getAnalyticalPercentile());
		analyPerTextField.setEditable(false);
		
		GRESubjectLabel = new JLabel("GRE Subject Taken: ");
		GRESubjectTextField = new JTextField(app.getSubjectTestTaken());
		GRESubjectTextField.setEditable(false);
		
		GRESubjectScoreLabel = new JLabel("Score: ");
		GRESubjectScoreTextField = new JTextField(app.getGRESubjectScore());
		GRESubjectScoreTextField.setEditable(false);

		TOEFLLabel = new JLabel("TOEFL Score: ");
		TOEFLScoureTextField = new JTextField(app.getTOEFLScore());
		TOEFLScoureTextField.setEditable(false);
		
		TOEFLCommentsLabel = new JLabel("Comments: ");
		TOEFLCommentsArea = new JTextArea(7, 50);
		TOEFLCommentsArea.setText(app.getTOEFLComments());
		TOEFLCommentsArea.setEnabled(false);
		TOEFLCommentsScrollPanel = new JScrollPane(TOEFLCommentsArea);
		
		IELTSLabel = new JLabel("IELTS: ");
		IELTSTextField = new JTextField(app.getIELTS());
		IELTSTextField.setEditable(false);
		
		programLabel = new JLabel("Program: ");
		programTextField = new JTextField(10);
		programTextField.setText(app.getProgram());
		programTextField.setEditable(false);
		
		indicateTopicLabel = new JLabel("Indicate Topic: ");
		indicateTopicTextField = new JTextField(10);
		indicateTopicTextField.setText(app.getIndicateTopics());
		indicateTopicTextField.setEditable(false);
		
		undergraduateRankLabel = new JLabel("Undergraduate Rank: ");
		undergraduateRankTextField = new JTextField(app.getUndergradRank());
		undergraduateRankTextField.setEditable(false);
		
		ugRankOfLabel = new JLabel("Out Of");
		ugRankOfField = new JTextField(10);
		ugRankOfField.setText(app.getUndergradOutof());
		ugRankOfField.setEditable(false);
		
		graduateRankLabel = new JLabel("Graduate Rank: ");
		graduateRankTextField = new JTextField(app.getGradRank());
		graduateRankTextField.setEditable(false);
		
		gRankOfLabel = new JLabel("Out Of");
		gRankOfField = new JTextField(10);
		gRankOfField.setText(app.getGradOutof());
		gRankOfField.setEditable(false);
		
		institution1Label = new JLabel("Institution 1: ");
		institution1TextField = new JTextField(app.getInstitution1());
		institution1TextField.setEditable(false);
		
		gradingScaleLabel1 = new JLabel("Grading Scale: ");
		gradingScaleField1 = new JTextField(app.getGradingScale1());
		gradingScaleField1.setEditable(false);
		
		institution2LabeL = new JLabel("Institution 2: ");
		institution2TextField = new JTextField(app.getInstitution2());
		institution2TextField.setEditable(false);
		
		gradingScaleLabel2 = new JLabel("Grading Scale: ");
		gradingScaleField2 = new JTextField(10);
		gradingScaleField2.setText(app.getGradingScale2());
		gradingScaleField2.setEditable(false);
		
		gpaLabel = new JLabel("GPA:");
		
		gpaYear1Label = new JLabel("Year 1: ");
		gpaYear1Field = new JTextField(10);
		gpaYear1Field.setText(app.getYear1GPA());
		gpaYear1Field.setEditable(false);
		
		gpaYear2Label = new JLabel("Year 2: ");
		gpaYear2Field = new JTextField(10);
		gpaYear2Field.setText(app.getYear2GPA());
		gpaYear2Field.setEditable(false);
		
		gpaYear3Label = new JLabel("Year 3: ");
		gpaYear3Field = new JTextField(10);
		gpaYear3Field.setText(app.getYear3GPA());
		gpaYear3Field.setEditable(false);
		
		gpaYear4Label = new JLabel("Year 4: ");
		gpaYear4Field = new JTextField(10);
		gpaYear4Field.setText(app.getYear4GPA());
		gpaYear4Field.setEditable(false);
		
		gpaYear5Label = new JLabel("Year 5: ");
		gpaYear5Field = new JTextField(10);
		gpaYear5Field.setText(app.getYear5GPA());
		gpaYear5Field.setEditable(false);
		
		gpaYear6Label = new JLabel("Year 6: ");
		gpaYear6Field = new JTextField(10);
		gpaYear6Field.setText(app.getYear6GPA());
		gpaYear6Field.setEditable(false);
		
		gpaYear7Label = new JLabel("Year 7: ");
		gpaYear7Field = new JTextField(10);
		gpaYear7Field.setText(app.getYear7GPA());
		gpaYear7Field.setEditable(false);
		
		theoryCourseLabel = new JLabel("Course Name: ");
		theoryCourseField = new JTextField(20);
		theoryCourseField.setText(app.getTheoryCourseTitle());
		theoryCourseField.setEditable(false);
		theoryScaleLabel = new JLabel("Grading Scale: ");
		theoryScaleField = new JTextField(20);
		theoryScaleField.setText(app.getTheoryGradingScale());
		theoryScaleField.setEditable(false);
		theoryGradeLabel = new JLabel("Grade: ");
		theoryGradeField = new JTextField(20);
		theoryGradeField.setText(app.getTheoryGrade());
		theoryGradeField.setEditable(false);
		theoryEquivLabel = new JLabel("USB Equivalent Course: ");
		theoryEquivField = new JTextField(20);
		theoryEquivField.setText(app.getTheoryUSBEquivalent1());
		theoryEquivField.setEditable(false);
		
		algorithmCourseLabel = new JLabel("Course Name: ");
		algorithmCourseField = new JTextField(20);
		algorithmCourseField.setText(app.getAlgoCourseTitle());
		algorithmCourseField.setEditable(false);
		algorithmScaleLabel = new JLabel("Grading Scale: ");
		algorithmScaleField = new JTextField(20);
		algorithmScaleField.setText(app.getAlgoGradingScale());
		algorithmScaleField.setEditable(false);
		algorithmGradeLabel = new JLabel("Grade: ");
		algorithmGradeField = new JTextField(20);
		algorithmGradeField.setText(app.getAlgoGrade());
		algorithmGradeField.setEditable(false);
		algorithmEquivLabel = new JLabel("USB Equivalent Course: ");
		algorithmEquivField = new JTextField(20);
		algorithmEquivField.setText(app.getAlgoUSBEquivalent1());
		algorithmEquivField.setEditable(false);
		
		proglangCourseLabel = new JLabel("Course Name: ");
		proglangCourseField = new JTextField(20);
		proglangCourseField.setText(app.getProLangCourseTitle());
		proglangCourseField.setEditable(false);
		proglangScaleLabel = new JLabel("Grading Scale: ");
		proglangScaleField = new JTextField(20);
		proglangScaleField.setText(app.getProLangGradingScale());
		proglangScaleField.setEditable(false);
		proglangGradeLabel = new JLabel("Grade: ");
		proglangGradeField = new JTextField(20);
		proglangGradeField.setText(app.getProLangGrade());
		proglangGradeField.setEditable(false);
		proglangEquivLabel = new JLabel("USB Equivalent Course: ");
		proglangEquivField = new JTextField(20);
		proglangEquivField.setText(app.getTheoryUSBEquivalent1());
		proglangEquivField.setEditable(false);
		
		osCourseLabel = new JLabel("Course Name: ");
		osCourseField = new JTextField(20);
		osCourseField.setEditable(false);
		osCourseField.setText(app.getOSCourseTitle());
		osScaleLabel = new JLabel("Grading Scale: ");
		osScaleField = new JTextField(20);
		osScaleField.setText(app.getOSGradingScale());
		osScaleField.setEditable(false);
		osGradeLabel = new JLabel("Grade: ");
		osGradeField = new JTextField(20);
		osGradeField.setText(app.getOSGrade());
		osGradeField.setEditable(false);
		osEquivLabel = new JLabel("USB Equivalent Course: ");
		osEquivField = new JTextField(20);
		osEquivField.setText(app.getOSUSBEquivalent1());
		osEquivField.setEditable(false);
		
		summaryLabel = new JLabel("Summary: ");
		summaryTextArea = new JTextArea(15, 100);
		summaryTextArea.setText(app.getSummary());
		summaryTextArea.setEnabled(false);
		summaryScrollPanel = new JScrollPane(summaryTextArea);
		
		acceptRadioButton = new JRadioButton("Accept", false);
		rejectRadioButton = new JRadioButton("Reject", false);
		reevaluateRadioButton = new JRadioButton("Re-evaluate", false);
		ButtonGroup group = new ButtonGroup();
		group.add(acceptRadioButton);
		group.add(rejectRadioButton);
		group.add(reevaluateRadioButton);
		if (!isChair){
			acceptRadioButton.setEnabled(false);
			rejectRadioButton.setEnabled(false);
			reevaluateRadioButton.setEnabled(false);
		}
		if(app.getStatus() != null)
		{
			if(app.getStatus().equals(acceptRadioButton.getText()))
				acceptRadioButton.setSelected(true);
			if(app.getStatus().equals(rejectRadioButton.getText()))
				rejectRadioButton.setSelected(true);
			if(app.getStatus().equals(reevaluateRadioButton.getText()))
				reevaluateRadioButton.setSelected(true);
		}
		
		backButton = new JButton("Back");
		okButton = new JButton("OK");
		viewReviewsButton = new JButton("View Reviews");
		if (!isChair)
			viewReviewsButton.setEnabled(false);
		addReviewButton = new JButton("Add Review");
		//if (user.getCompletedReview() >= user.getNumAssignedReviews())
			//addReviewButton.setEnabled(false);
		enableEditingButton = new JButton("Enable Editing");
		if (!isChair)
			enableEditingButton.setEnabled(false);
		viewFileButton = new JButton("Open Related File");
		
		editPanel.add(viewReviewsButton);
		editPanel.add(addReviewButton);
		editPanel.add(enableEditingButton);
		editPanel.add(viewFileButton);
		
		buttonPanel = new JPanel();
		buttonPanel.setLayout(new FlowLayout(FlowLayout.RIGHT));
		buttonPanel.add(backButton);
		buttonPanel.add(okButton);
		
		evaluatePanel.add(acceptRadioButton);
		evaluatePanel.add(rejectRadioButton);
		evaluatePanel.add(reevaluateRadioButton);
		
		controlPanel.add(editPanel, BorderLayout.NORTH);
		controlPanel.add(evaluatePanel, BorderLayout.CENTER);
		controlPanel.add(buttonPanel, BorderLayout.SOUTH);

		basicInfoPanel.setLayout(new GridBagLayout());
		addComponent(appNumLabel,				basicInfoPanel,	0,	0,	1,	1);
		addComponent(submissionDateLabel,		basicInfoPanel,	4,	0,	1,	1);
		addComponent(submissionDateField,		basicInfoPanel,	5,	0,	1,	1);
		addComponent(numDesireReviewsLabel,		basicInfoPanel,	0,	1,	1,	1);
		addComponent(numDesireReviewsField,		basicInfoPanel,	1,	1,	1,	1);
		addComponent(tierLabel,					basicInfoPanel,	2,	1,	1,	1);
		addComponent(tierTextField,				basicInfoPanel,	3,	1,	1,	1);
		//addComponent(tierStateLabel,			basicInfoPanel,	6,	1,	1,	1);
		addComponent(nameLabel,					basicInfoPanel,	0,	2,	1,	1);
		addComponent(nameTextField,				basicInfoPanel,	1,	2,	1,	1);
		addComponent(genderLabel,				basicInfoPanel,	2,	2,	1,	1);
		addComponent(genderTextField,			basicInfoPanel,	3,	2,	1,	1);
		addComponent(DOBLabel,					basicInfoPanel,	4,	2,	1,	1);
		addComponent(DOBTextField,				basicInfoPanel,	5,	2,	1,	1);
		addComponent(emailLabel,				basicInfoPanel,	0,	3,	1,	1);
		addComponent(emailTextField,			basicInfoPanel,	1,	3,	1,	1);
		addComponent(phoneLabel,				basicInfoPanel,	2,	3,	1,	1);
		addComponent(phoneField,				basicInfoPanel,	3,	3,	1,	1);
		addComponent(ethnicityLabel,			basicInfoPanel,	0,	4,	1,	1);
		addComponent(ethnicityField,			basicInfoPanel,	1,	4,	1,	1);
		addComponent(raceLabel,					basicInfoPanel,	2,	4,	1,	1);
		addComponent(raceField,					basicInfoPanel,	3,	4,	1,	1);
		addComponent(citizenLabel,				basicInfoPanel,	4,	4,	1,	1);
		addComponent(citizenField,				basicInfoPanel,	5,	4,	1,	1);
		addComponent(pResidentLabel,			basicInfoPanel,	0,	5,	1,	1);
		addComponent(pResidentTextField,		basicInfoPanel,	1,	5,	1,	1);	
		addComponent(SBUIDLabel,				basicInfoPanel,	0,	6,	1,	1);
		addComponent(SBUIDTextField,			basicInfoPanel,	1,	6,	1,	1);
		addComponent(appTypeLabel,				basicInfoPanel,	2,	6,	1,	1);
		addComponent(appTypeField,				basicInfoPanel,	3,	6,	1,	1);
		
		testInfoPanel.setLayout(new GridBagLayout());
		addComponent(GRELabel,					testInfoPanel,	0,	2,	1,	1);
		addComponent(verbalLabel,				testInfoPanel,	0,	3,	1,	1);
		addComponent(verbalTextField,			testInfoPanel,	1,	3,	1,	1);
		addComponent(verbalPerLabel,			testInfoPanel,	2,	3,	1,	1);
		addComponent(verbalPerTextField,		testInfoPanel,	3,	3,	1,	1);
		addComponent(quantitativeLabel,			testInfoPanel,	0,	4,	1,	1);
		addComponent(quantitativeTextField,		testInfoPanel,	1,	4,	1,	1);
		addComponent(quanPerLabel,				testInfoPanel,	2,	4,	1,	1);
		addComponent(quanPerTextField,			testInfoPanel,	3,	4,	1,	1);
		addComponent(analyticalLabel,			testInfoPanel,	0,	5,	1,	1);
		addComponent(analyticalTextField,		testInfoPanel,	1,	5,	1,	1);
		addComponent(analyPerLabel,				testInfoPanel,	2,	5,	1,	1);
		addComponent(analyPerTextField,			testInfoPanel,	3,	5,	1,	1);
		addComponent(GRESubjectLabel,			testInfoPanel,	0,	6,	1,	1);
		addComponent(GRESubjectTextField,		testInfoPanel,	1,	6,	1,	1);
		addComponent(GRESubjectScoreLabel,		testInfoPanel,	2,	6,	1,	1);
		addComponent(GRESubjectScoreTextField,	testInfoPanel,	3,	6,	1,	1);
		addComponent(IELTSLabel,				testInfoPanel,	0,	7,	1,	1);
		addComponent(IELTSTextField,			testInfoPanel,	1,	7,	1,	1);
		addComponent(TOEFLLabel,				testInfoPanel,	0,	8,	1,	1);
		addComponent(TOEFLScoureTextField,		testInfoPanel,	1,	8,	1,	1);
		addComponent(TOEFLNetLabel,				testInfoPanel,	2,	8,	1,	1);
		addComponent(TOEFLNetField,				testInfoPanel,	3,	8,	1,	1);
		addComponent(TOEFLCommentsLabel,		testInfoPanel,	0,	9,	1,	1);
		addComponent(TOEFLCommentsScrollPanel,	testInfoPanel,	0,	10,	5,	1);
		
		academicInfoPanel.setLayout(new GridBagLayout());
		addComponent(SBUGPALabel,				academicInfoPanel,	0,	1,	1,	1);
		addComponent(SBUGPATextField,			academicInfoPanel,	1,	1,	1,	1);
		addComponent(programLabel,				academicInfoPanel,	2,	1,	1,	1);
		addComponent(programTextField,			academicInfoPanel,	3,	1,	1,	1);
		addComponent(indicateTopicLabel,		academicInfoPanel,	4,	1,	1,	1);
		addComponent(indicateTopicTextField,	academicInfoPanel,	5,	1,	1,	1);
		addComponent(undergraduateRankLabel,	academicInfoPanel,	0,	3,	1,	1);
		addComponent(undergraduateRankTextField,academicInfoPanel,	1,	3,	1,	1);
		addComponent(ugRankOfLabel,				academicInfoPanel,	2,	3,	1,	1);
		addComponent(ugRankOfField,				academicInfoPanel,	3,	3,	1,	1);
		addComponent(graduateRankLabel,			academicInfoPanel,	0,	4,	1,	1);
		addComponent(graduateRankTextField,		academicInfoPanel,	1,	4,	1,	1);
		addComponent(gRankOfLabel,				academicInfoPanel,	2,	4,	1,	1);
		addComponent(gRankOfField,				academicInfoPanel,	3,	4,	1,	1);
		addComponent(institution1Label,			academicInfoPanel,	0,	12,	1,	1);
		addComponent(institution1TextField,		academicInfoPanel,	1,	12,	1,	1);
		addComponent(gradingScaleLabel1,		academicInfoPanel,	2,	12,	1,	1);
		addComponent(gradingScaleField1,		academicInfoPanel,	3,	12,	1,	1);
		addComponent(institution2LabeL,			academicInfoPanel,	4,	12,	1,	1);
		addComponent(institution2TextField,		academicInfoPanel,	5,	12,	1,	1);
		addComponent(gradingScaleLabel2,		academicInfoPanel,	6,	12,	1,	1);
		addComponent(gradingScaleField2,		academicInfoPanel,	7,	12,	1,	1);
		addComponent(gpaLabel,					academicInfoPanel,	0,	13,	1,	1);
		addComponent(gpaYear1Label,				academicInfoPanel,	0,	14,	1,	1);
		addComponent(gpaYear1Field,				academicInfoPanel,	1,	14,	1,	1);
		addComponent(gpaYear6Label,				academicInfoPanel,	4,	14,	1,	1);
		addComponent(gpaYear6Field,				academicInfoPanel,	5,	14,	1,	1);
		addComponent(gpaYear2Label,				academicInfoPanel,	0,	15,	1,	1);
		addComponent(gpaYear2Field,				academicInfoPanel,	1,	15,	1,	1);
		addComponent(gpaYear7Label,				academicInfoPanel,	4,	15,	1,	1);
		addComponent(gpaYear7Field,				academicInfoPanel,	5,	15,	1,	1);
		addComponent(gpaYear3Label,				academicInfoPanel,	0,	16,	1,	1);
		addComponent(gpaYear3Field,				academicInfoPanel,	1,	16,	1,	1);
		addComponent(gpaYear4Label,				academicInfoPanel,	0,	17,	1,	1);
		addComponent(gpaYear4Field,				academicInfoPanel,	1,	17,	1,	1);
		addComponent(gpaYear5Label,				academicInfoPanel,	0,	18,	1,	1);
		addComponent(gpaYear5Field,				academicInfoPanel,	1,	18,	1,	1);

		classInfoPanel.setLayout(new GridBagLayout());
		addComponent(theoryCourseLabel,				classInfoPanel,	0,	0,	1,	1);
		addComponent(theoryCourseField,				classInfoPanel,	1,	0,	1,	1);
		addComponent(theoryScaleLabel,				classInfoPanel,	2,	0,	1,	1);
		addComponent(theoryScaleField,				classInfoPanel,	3,	0,	1,	1);
		addComponent(theoryGradeLabel,				classInfoPanel,	0,	1,	1,	1);
		addComponent(theoryGradeField,				classInfoPanel,	1,	1,	1,	1);
		addComponent(theoryEquivLabel,				classInfoPanel,	2,	1,	1,	1);
		addComponent(theoryEquivField,				classInfoPanel,	3,	1,	1,	1);
		addComponent(algorithmCourseLabel,			classInfoPanel,	0,	2,	1,	1);
		addComponent(algorithmCourseField,			classInfoPanel,	1,	2,	1,	1);
		addComponent(algorithmScaleLabel,			classInfoPanel,	2,	2,	1,	1);
		addComponent(algorithmScaleField,			classInfoPanel,	3,	2,	1,	1);
		addComponent(algorithmGradeLabel,			classInfoPanel,	0,	3,	1,	1);
		addComponent(algorithmGradeField,			classInfoPanel,	1,	3,	1,	1);
		addComponent(algorithmEquivLabel,			classInfoPanel,	2,	3,	1,	1);
		addComponent(algorithmEquivField,			classInfoPanel,	3,	3,	1,	1);
		addComponent(proglangCourseLabel,			classInfoPanel,	0,	4,	1,	1);
		addComponent(proglangCourseField,			classInfoPanel,	1,	4,	1,	1);
		addComponent(proglangScaleLabel,			classInfoPanel,	2,	4,	1,	1);
		addComponent(proglangScaleField,			classInfoPanel,	3,	4,	1,	1);
		addComponent(proglangGradeLabel,			classInfoPanel,	0,	5,	1,	1);
		addComponent(proglangGradeField,			classInfoPanel,	1,	5,	1,	1);
		addComponent(proglangEquivLabel,			classInfoPanel,	2,	5,	1,	1);
		addComponent(proglangEquivField,			classInfoPanel,	3,	5,	1,	1);
		addComponent(osCourseLabel,					classInfoPanel,	0,	6,	1,	1);
		addComponent(osCourseField,					classInfoPanel,	1,	6,	1,	1);
		addComponent(osScaleLabel,					classInfoPanel,	2,	6,	1,	1);
		addComponent(osScaleField,					classInfoPanel,	3,	6,	1,	1);
		addComponent(osGradeLabel,					classInfoPanel,	0,	7,	1,	1);
		addComponent(osGradeField,					classInfoPanel,	1,	7,	1,	1);
		addComponent(osEquivLabel,					classInfoPanel,	2,	7,	1,	1);
		addComponent(osEquivField,					classInfoPanel,	3,	7,	1,	1);

		
		if(!(ots == null))
		{
		GREVLabel = new JLabel("Verbal: ");
		GREVField = new JTextField(20);
		GREVField.setEditable(false);
		GREVField.setText(ots.getOffGREV());
		
		GREVPLabel = new JLabel("Verbal Percentile: ");
		GREVPField = new JTextField(20);
		GREVPField.setEditable(false);
		GREVPField.setText(ots.getOffGREVPct());
		
		GREQLabel = new JLabel("Quantitative: ");
		GREQField = new JTextField(20);
		GREQField.setEditable(false);
		GREQField.setText(ots.getOffGREQ());
		
		GREQPLabel = new JLabel("Quantitative Percentile: ");
		GREQPField = new JTextField(20);
		GREQPField.setEditable(false);
		GREQPField.setText(ots.getOffGREQPct());
		
		GREALabel = new JLabel("Analytical: ");
		GREAField = new JTextField(20);
		GREAField.setEditable(false);
		GREAField.setText(ots.getOffGREA());
		
		GREAPLabel = new JLabel("Analytical Percentile: ");
		GREAPField = new JTextField(20);
		GREAPField.setEditable(false);
		GREAPField.setText(ots.getOffGREAPct());
		
		GRESubLabel = new JLabel("Subject Test Taken: ");
		GRESubField = new JTextField(20);
		GRESubField.setEditable(false);
		GRESubField.setText(ots.getOffGRESbName());
		
		GRESubSLabel = new JLabel("GRE Subject Score: ");
		GRESubSField = new JTextField(20);
		GRESubSField.setEditable(false);
		GRESubSField.setText(ots.getOffGRESb());
		
		GRESubPLabel = new JLabel("Subject Test Percentile: ");
		GRESubPField = new JTextField(20);
		GRESubPField.setEditable(false);
		GRESubPField.setText(ots.getOffGRESbPct());
		
		toeflTLabel = new JLabel("TOEFL IBT Total Score: "); 
		toeflTField  = new JTextField(20);
		toeflTField.setEditable(false);
		toeflTField.setText(ots.getOffTOEFLT());
		
		toeflRLabel = new JLabel("TOEFL IBT Reading: "); 
		toeflRField  = new JTextField(20);
		toeflRField.setEditable(false);
		toeflRField.setText(ots.getOffTOEFLR());
		
		toeflSLabel = new JLabel("TOEFL IBT Speaking: "); 
		toeflSField  = new JTextField(20);
		toeflSField.setEditable(false);
		toeflSField.setText(ots.getOffTOEFLS());
		
		toeflLLabel = new JLabel("TOEFL IBT Listening: "); 
		toeflLField  = new JTextField(20);
		toeflLField.setEditable(false);
		toeflLField.setText(ots.getOffTOEFLL());
		
		toeflWLabel = new JLabel("TOEFL IBT Writing: "); 
		toeflWField  = new JTextField(20);
		toeflWField.setEditable(false);
		toeflWField.setText(ots.getOffTOEFLW());
		
		otsPanel.setLayout(new GridBagLayout());
		addComponent(GREVLabel,				otsPanel,	0,	0,	1,	1);
		addComponent(GREVField,				otsPanel,	1,	0,	1,	1);
		addComponent(GREVPLabel,			otsPanel,	2,	0,	1,	1);
		addComponent(GREVPField,			otsPanel,	3,	0,	1,	1);
		addComponent(GREQLabel,				otsPanel,	0,	1,	1,	1);
		addComponent(GREQField,				otsPanel,	1,	1,	1,	1);
		addComponent(GREQPLabel,			otsPanel,	2,	1,	1,	1);
		addComponent(GREQPField,			otsPanel,	3,	1,	1,	1);
		addComponent(GREALabel,				otsPanel,	0,	2,	1,	1);
		addComponent(GREAField,				otsPanel,	1,	2,	1,	1);
		addComponent(GREAPLabel,			otsPanel,	2,	2,	1,	1);
		addComponent(GREAPField,			otsPanel,	3,	2,	1,	1);
		addComponent(GRESubLabel,			otsPanel,	0,	3,	1,	1);
		addComponent(GRESubField,			otsPanel,	1,	3,	1,	1);
		addComponent(GRESubSLabel,			otsPanel,	0,	4,	1,	1);
		addComponent(GRESubSField,			otsPanel,	1,	4,	1,	1);
		addComponent(GRESubPLabel,			otsPanel,	2,	4,	1,	1);
		addComponent(GRESubPField,			otsPanel,	3,	4,	1,	1);
		addComponent(toeflTLabel,			otsPanel,	0,	5,	1,	1);
		addComponent(toeflTField,			otsPanel,	1,	5,	1,	1);
		addComponent(toeflRLabel,			otsPanel,	0,	6,	1,	1);
		addComponent(toeflRField,			otsPanel,	1,	6,	1,	1);
		addComponent(toeflSLabel,			otsPanel,	2,	6,	1,	1);
		addComponent(toeflSField,			otsPanel,	3,	6,	1,	1);
		addComponent(toeflLLabel,			otsPanel,	0,	7,	1,	1);
		addComponent(toeflLField,			otsPanel,	1,	7,	1,	1);
		addComponent(toeflWLabel,			otsPanel,	2,	7,	1,	1);
		addComponent(toeflWField,			otsPanel,	3,	7,	1,	1);
		}
		
		summaryPanel.setLayout(new GridBagLayout());
		addComponent(summaryLabel,				summaryPanel,	0,	0,	1,	1);
		addComponent(summaryScrollPanel,		summaryPanel,	0,	1,	8,	1);
		
		tabbedPane.addTab( "Basic Info", basicInfoPanel );
		tabbedPane.addTab( "Test", testInfoPanel );
		tabbedPane.addTab( "Official Test Score", otsPanel );
		tabbedPane.addTab( "Academic", academicInfoPanel );
		tabbedPane.addTab( "Class History", classInfoPanel );
		tabbedPane.addTab( "Summary", summaryPanel );
		
		this.add(tabbedPane, BorderLayout.CENTER);
		this.add(controlPanel, BorderLayout.SOUTH);
		
		backHandler = new BackHandler();
		viewReviewsHandler = new ViewReviewsHandler();
		addReviewHandler = new AddReviewHandler();
		enableEditingHandler = new EnableEditingHandler();
		okHandler = new OKHandler();
		viewFileHandler = new ViewFileHandler();
		radioButtonHandler = new RadioButtonHandler();
		
		backButton.addActionListener(backHandler);
		viewReviewsButton.addActionListener(viewReviewsHandler);
		addReviewButton.addActionListener(addReviewHandler);
		enableEditingButton.addActionListener(enableEditingHandler);
		okButton.addActionListener(okHandler);
		viewFileButton.addActionListener(viewFileHandler);
		acceptRadioButton.addActionListener(radioButtonHandler);
		rejectRadioButton.addActionListener(radioButtonHandler);
		reevaluateRadioButton.addActionListener(radioButtonHandler);
	}
	
	public void addComponent(	JComponent jc,
			Container c,
			int x,
			int y,
			int w,
			int h)
	{
		GridBagConstraints gbc = new GridBagConstraints();
		gbc.gridx = x;
		gbc.gridy = y;
		gbc.gridwidth = w;
		gbc.gridheight = h;
		gbc.fill = GridBagConstraints.HORIZONTAL;
		gbc.insets = new Insets(0, 0, 25, 30);
		c.add(jc, gbc);
	}
	
	public static void main(String[] args)
	{	
		File file1 = new File("AY(New).txt");
		File file2 = new File("AY-map.txt");
		File file3 = new File("OTS.txt");
		File file4 = new File("OTS-map.txt");
		ApplicationManagerCloud formatter = new ApplicationManagerCloud(null, file1, file2, file3, file4);
		UserManager um = new UserManager();
		ReviewManager rm = new ReviewManager(um);
		um.login("chair", "abc");
		viewAppFrame tmp = new viewAppFrame(formatter.getAllApps().get("alan_perlis@amail.com"), formatter.getAllScore().get("alan_perlis@amail.com"),um);
		tmp.setVisible(true);
	}
	
	class BackHandler implements ActionListener
	{
		public void actionPerformed(ActionEvent arg0) 
		{
			ApplicationManagerCloud ap = ApplicationManagerCloud.getAppManager();
			SelectStudentFrame temp = new SelectStudentFrame(um, ap.getAllApps());
			temp.setVisible(true);
			viewAppFrame.this.setVisible(false);
		}
	}
	
	class ViewReviewsHandler implements ActionListener
	{
		public void actionPerformed(ActionEvent arg0) 
		{
			ReviewManager rm = ReviewManager.getRvManager();
			viewReviews temp = new viewReviews(app,viewAppFrame.this,rm, um);
			temp.setVisible(true);
		}
		
	}
	
	class RadioButtonHandler implements ActionListener
	{
		public void actionPerformed(ActionEvent e) 
		{
			if(acceptRadioButton.isSelected() == true)		
				app.setStatus(acceptRadioButton.getText());
			else if(rejectRadioButton.isSelected() == true)
				app.setStatus(rejectRadioButton.getText());
			else if(reevaluateRadioButton.isSelected() == true)
				app.setStatus(reevaluateRadioButton.getText());
		}
		
	}
	
	class AddReviewHandler implements ActionListener
	{
		public void actionPerformed(ActionEvent arg0) 
		{	
			ReviewManager rm  = ReviewManager.getRvManager();
			AddReviewDialog temp = new AddReviewDialog(app, (Reviewer)user, rm);
			temp.setVisible(true);
		}		
	}
	
	class ViewFileHandler implements ActionListener
	{
		public void actionPerformed(ActionEvent arg0) 
		{	
			try                                    
	        {
				File dir = new File("files\\"+app.getEmailAddress());
				File[] children = dir.listFiles();
				if(children[0] == null)
				{
					JOptionPane.showMessageDialog(viewAppFrame.this, "This application currently have no related file", "No file",JOptionPane.INFORMATION_MESSAGE);
				}
				else
				{
					for(int i = 0; i < children.length; i++)
					{
						System.out.println(children[i]);
						try                                      //try statement
				        {
							Runtime.getRuntime().exec("rundll32 url.dll,FileProtocolHandler " + children[i].getPath());
			
				        } 
				        catch (Exception e)                    //catch any exceptions here
				        {
				        	System.out.println("Error" + e );  //print the error
				        }
					}
				}
	        }
			catch (Exception e) 
			{
				JOptionPane.showMessageDialog(viewAppFrame.this, "No file found", "No file",JOptionPane.INFORMATION_MESSAGE);
			}
		}		
	}
	
	class EnableEditingHandler implements ActionListener
	{
		public void actionPerformed(ActionEvent arg0) 
		{
			tierTextField.setEnabled(true);
			SBUIDTextField.setEnabled(true);
			SBUGPATextField.setEnabled(true);
			TOEFLCommentsArea.setEnabled(true);
			summaryTextArea.setEnabled(true);
		}
		
	}
	class OKHandler implements ActionListener
	{
		public void actionPerformed(ActionEvent arg0) 
		{
			app.setTier(tierTextField.getText());
			app.setSBUID(SBUIDTextField.getText());
			app.setSBUGPA(SBUGPATextField.getText());
			app.setTOEFLComments(TOEFLCommentsArea.getText());
			app.setSummary(summaryTextArea.getText());

			viewAppFrame.this.setVisible(false);
		}
	}
}
